<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<style>
		#menu {position:relative; float:left; margin-left:400px}
		a {text-decoration:none}
	</style>
	<title></title>
</head>
<body>
	<div>
		<?php
		if(isset($_POST["confirmar"])){
			$login = $_POST['login'];
			$senha = $_POST['senha'];
			exec("sudo smbldap-useradd -a $login");
		
			$cmdsenha = "( echo {$senha} ; echo {$senha} ) | sudo smbldap-passwd {$login}";
			exec($cmdsenha);
	
			#exec("echo -e \"$senha\n$senha\" | sudo smbldap-passwd $login");
			$grupos = $_POST['list_groups'];
			if(count($grupos) == 1){
				$primeiro = array_shift($grupos);
				exec("sudo smbldap-usermod -G {$primeiro} {$login}");
			}else{
				foreach($grupos as $grupo){
					exec("sudo smbldap-usermod -G +{$grupo} {$login}");	
				}
			}
		}
		if(isset($_POST['prim_name'])){
			$prim_name = $_POST['prim_name'];
			exec("sudo smbldap-usermod -N $prim_name $login");
		}
		if(isset($_POST['sb_name'])){
			$sb_name = $_POST['sb_name'];
			exec("sudo smbldap-usermod -S $sb_name $login");
		}
		if(isset($_POST['compl_name'])){
			$compl_name = $_POST['compl_name'];
			exec("sudo smbldap-usermod -c \"$compl_name\" $login");
		}
		if(isset($_POST['setor'])){
			$setor = $_POST['setor'];
			exec("sudo smbldap-userinfo -r $setor $login");
		}
		#if(isset($_POST['mail'])){
		#	$mail = $_POST['mail'];
		#	echo "sudo smbldap-usermod -T $mail $login";
		#}
		if(isset($_POST['telephone'])){
			$tell = $_POST['telephone'];
			exec("sudo smbldap-userinfo -h $tell $login");
		}
		if(isset($_POST['ramal_setor'])){
			$ramal = $_POST['ramal_setor'];
			exec("sudo smbldap-userinfo -w $ramal $login");
		}
		if(isset($_POST['dsb'])){
			$dsb = $_POST['dsb'];
			if($dsb == "-I"){
				exec("sudo smbldap-usermod $dsb $login");
			}
		}
		if(isset($_POST['mdfpasswd'])){
			$mdf = $_POST['mdfpasswd'];
			if($mdf == 1){
				exec("sudo smbldap-usermod -A 1 $login");
			}else{
				exec("sudo smbldap-usermod -A 0 $login");
			}
		}
		if(isset($_POST['dir'])){
			$home = $_POST['dir'];
			exec("sudo smbldap-usermod -D $home $login");
		}
		if(isset($_POST['log_scr'])){
			$scr = $_POST['log_scr'];
			exec("sudo smbldap-usermod -E $scr $login");
		}
		echo "<p>" . "Usuário cadastrado com sucesso!" . "</p>";
		?>
	</div>
	<div id="menu">
		<p><a href="index.php">Pagina Inicial</a> / <a href="cadastro.php">Voltar</a> / <a href="<?php echo "autenticar.php?acao=logout";?>">Sair</a></p>
	</div>
</body>
</html>
